<template>
  <div>
    <div class="layout-content">
      <NavBar :meta="this.$route.meta"></NavBar>
      <keep-alive v-if="$route.meta.keepAlive">
        <router-view></router-view>
      </keep-alive>
      <router-view v-else></router-view>
    </div>
    <div class="layout-footer">
      <TabBar :data="tabbars" @change="handleChange" />
    </div>
  </div>
</template>

<script>
import TabBar from '@/components/TabBar'
import { constantRouterMap } from '@/router/router.config'
import NavBar from 'components/NavBar'
export default {
  name: 'AppLayout',
  data() {
    return {
      tabbars: this.generatePath()
    }
  },
  components: {
    NavBar,
    TabBar
  },
  methods: {
    generatePath() {
      const res = []
      for (const config of constantRouterMap) {
        if (config.path === '/') {
          const content = config.children
          for (const path of content) {
            res.push({
              title: path.meta.title,
              to: {
                name: path.name
              },
              icon: path.meta.icon
            })
          }
        }
      }
      console.log(res)
      return res
    },
    handleChange(v) {
      console.log('tab value:', v)
    }
  }
}
</script>
